#!/bin/bash

prefix=/web/mysql

function isRun()
{
    safe=$(ps -aux | grep mysqld_safe | grep -v 'grep' | awk '{print $2}')
    test -z $safe && echo "close" || echo $safe
}

function stop() {
    safe=$(isRun)
    test "$safe" == "close" && return

    mysqld=$(cat $prefix/run/mysqld.pid)
    kill -9 $safe
    kill -9 $mysqld
}

function start() {
    test "$(isRun)" != "close" && return
    $prefix/bin/mysqld_safe --defaults-file=$prefix/etc/my.cnf &
}

function restart() {
    stop
    start
}

function status() {
    test "$(isRun)" == "close" && echo "kyo mysql server 5.7 is stop!" \
        || echo "kyo mysql server 5.7 is Running..."
}

function myexit() {
    echo $1
    exit $2
}

test $UID -ne 0 && myexit '请使用sudo执行或切换root执行!'

${1-start}
